home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / NFSD / NFSFH.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  5KB  |  214 lines

  1. /*
  2.  * include/linux/nfsd/nfsfh.h
  3.  *
  4.  * This file describes the layout of the file handles as passed
  5.  * over the wire.
  6.  *
  7.  * Earlier versions of knfsd used to sign file handles using keyed MD5
  8.  * or SHA. I've removed this code, because it doesn't give you more
  9.  * security than blocking external access to port 2049 on your firewall.
  10.  *
  11.  * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
  12.  */
  13.  
  14. #ifndef NFSD_FH_H
  15. #define NFSD_FH_H
  16.  
  17. #include <linux/types.h>
  18. #include <linux/string.h>
  19. #include <linux/fs.h>
  20. #include <linux/nfsd/const.h>
  21. #include <linux/nfsd/debug.h>
  22.  
  23. /*
  24.  * This is the new "dentry style" Linux NFSv2 file handle.
  25.  *
  26.  * The xino and xdev fields are currently used to transport the
  27.  * ino/dev of the exported inode.
  28.  */
  29. struct nfs_fhbase {
  30.     struct dentry *    fb_dentry;    /* dentry cookie */
  31.     __u32        fb_ino;        /* our inode number */
  32.     __u32        fb_dirino;    /* dir inode number */
  33.     __u32        fb_dev;        /* our device */
  34.     __u32        fb_xdev;
  35.     __u32        fb_xino;
  36. };
  37.  
  38. #define NFS_FH_PADDING        (NFS_FHSIZE - sizeof(struct nfs_fhbase))
  39. struct knfs_fh {
  40.     struct nfs_fhbase    fh_base;
  41.     __u8            fh_cookie[NFS_FH_PADDING];
  42. };
  43.  
  44. #define fh_dcookie        fh_base.fb_dentry
  45. #define fh_ino            fh_base.fb_ino
  46. #define fh_dirino        fh_base.fb_dirino
  47. #define fh_dev            fh_base.fb_dev
  48. #define fh_xdev            fh_base.fb_xdev
  49. #define fh_xino            fh_base.fb_xino
  50.  
  51. #ifdef __KERNEL__
  52.  
  53. /*
  54.  * Conversion macros for the filehandle fields.
  55.  */
  56. extern inline __u32 kdev_t_to_u32(kdev_t dev)
  57. {
  58.     return (__u32) dev;
  59. }
  60.  
  61. extern inline kdev_t u32_to_kdev_t(__u32 udev)
  62. {
  63.     return (kdev_t) udev;
  64. }
  65.  
  66. extern inline __u32 ino_t_to_u32(ino_t ino)
  67. {
  68.     return (__u32) ino;
  69. }
  70.  
  71. extern inline ino_t u32_to_ino_t(__u32 uino)
  72. {
  73.     return (ino_t) uino;
  74. }
  75.  
  76. /*
  77.  * This is the internal representation of an NFS handle used in knfsd.
  78.  * pre_mtime/post_version will be used to support wcc_attr's in NFSv3.
  79.  */
  80. typedef struct svc_fh {
  81.     struct knfs_fh        fh_handle;    /* FH data */
  82.     struct dentry *        fh_dentry;    /* validated dentry */
  83.     struct svc_export *    fh_export;    /* export pointer */
  84.     size_t            fh_pre_size;    /* size before operation */
  85.     time_t            fh_pre_mtime;    /* mtime before oper */
  86.     time_t            fh_pre_ctime;    /* ctime before oper */
  87.     unsigned long        fh_post_version;/* inode version after oper */
  88.     unsigned char        fh_locked;    /* inode locked by us */
  89.     unsigned char        fh_dverified;    /* dentry has been checked */
  90. } svc_fh;
  91.  
  92. /*
  93.  * Shorthand for dprintk()'s
  94.  */
  95. #define SVCFH_DENTRY(f)        ((f)->fh_dentry)
  96. #define SVCFH_INO(f)        ((f)->fh_handle.fh_ino)
  97. #define SVCFH_DEV(f)        ((f)->fh_handle.fh_dev)
  98.  
  99. /*
  100.  * Function prototypes
  101.  */
  102. u32    fh_verify(struct svc_rqst *, struct svc_fh *, int, int);
  103. void    fh_compose(struct svc_fh *, struct svc_export *, struct dentry *);
  104. void    fh_update(struct svc_fh *);
  105. void    fh_put(struct svc_fh *);
  106. void    nfsd_fh_flush(kdev_t);
  107. void    nfsd_fh_init(void);
  108. void    nfsd_fh_free(void);
  109.  
  110. void    expire_all(void);
  111. void    expire_by_dentry(struct dentry *);
  112.  
  113. static __inline__ struct svc_fh *
  114. fh_copy(struct svc_fh *dst, struct svc_fh *src)
  115. {
  116.     if (src->fh_dverified || src->fh_locked) {
  117.         struct dentry *dentry = src->fh_dentry;
  118.         printk(KERN_ERR "fh_copy: copying %s/%s, already verified!\n",
  119.             dentry->d_parent->d_name.name, dentry->d_name.name);
  120.     }
  121.             
  122.     *dst = *src;
  123.     return dst;
  124. }
  125.  
  126. static __inline__ struct svc_fh *
  127. fh_init(struct svc_fh *fhp)
  128. {
  129.     memset(fhp, 0, sizeof(*fhp));
  130.     return fhp;
  131. }
  132.  
  133. /*
  134.  * Lock a file handle/inode
  135.  */
  136. static inline void
  137. fh_lock(struct svc_fh *fhp)
  138. {
  139.     struct dentry    *dentry = fhp->fh_dentry;
  140.     struct inode    *inode;
  141.  
  142.     /*
  143.     dfprintk(FILEOP, "nfsd: fh_lock(%x/%ld) locked = %d\n",
  144.             SVCFH_DEV(fhp), SVCFH_INO(fhp), fhp->fh_locked);
  145.      */
  146.     if (!fhp->fh_dverified) {
  147.         printk(KERN_ERR "fh_lock: fh not verified!\n");
  148.         return;
  149.     }
  150.     if (fhp->fh_locked) {
  151.         printk(KERN_WARNING "fh_lock: %s/%s already locked!\n",
  152.             dentry->d_parent->d_name.name, dentry->d_name.name);
  153.         return;
  154.     }
  155.  
  156.     inode = dentry->d_inode;
  157.     down(&inode->i_sem);
  158.     if (!fhp->fh_pre_mtime)
  159.         fhp->fh_pre_mtime = inode->i_mtime;
  160.     fhp->fh_locked = 1;
  161. }
  162.  
  163. /*
  164.  * Unlock a file handle/inode
  165.  */
  166. static inline void
  167. fh_unlock(struct svc_fh *fhp)
  168. {
  169.     if (!fhp->fh_dverified)
  170.         printk(KERN_ERR "fh_unlock: fh not verified!\n");
  171.  
  172.     if (fhp->fh_locked) {
  173.         struct dentry *dentry = fhp->fh_dentry;
  174.         struct inode *inode = dentry->d_inode;
  175.  
  176.         if (!fhp->fh_post_version)
  177.             fhp->fh_post_version = inode->i_version;
  178.         fhp->fh_locked = 0;
  179.         up(&inode->i_sem);
  180.     }
  181. }
  182.  
  183. /*
  184.  * Release an inode
  185.  */
  186. #if 0
  187. #define fh_put(fhp)    __fh_put(fhp, __FILE__, __LINE__)
  188.  
  189. static inline void
  190. __fh_put(struct svc_fh *fhp, char *file, int line)
  191. {
  192.     struct dentry    *dentry;
  193.  
  194.     if (!fhp->fh_dverified)
  195.         return;
  196.  
  197.     dentry = fhp->fh_dentry;
  198.     if (!dentry->d_count) {
  199.         printk("nfsd: trying to free free dentry in %s:%d\n"
  200.                "      file %s/%s\n",
  201.                file, line,
  202.                dentry->d_parent->d_name.name, dentry->d_name.name);
  203.     } else {
  204.         fh_unlock(fhp);
  205.         fhp->fh_dverified = 0;
  206.         dput(dentry);
  207.     }
  208. }
  209. #endif
  210.  
  211. #endif /* __KERNEL__ */
  212.  
  213. #endif /* NFSD_FH_H */
  214.